﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PwdMgr.DataAccess;
using System.IO;

namespace PwdMgr.DataAccess.SQLite
{
    public class SQLiteDataAccessManager : IDataAccessManager
    {
        #region IDataAccessManager Members

        public IDataAccess CreateInstance(bool openInstance = false)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;

            string conn = string.Format("Data Source={0}", 
                Path.Combine(path, "App_Data\\test.db3"));
            SQLiteDataAccess da = new SQLiteDataAccess(conn);
            if (openInstance)
            {
                Open(da);
            }

            return da;
        }

        public void Open(IDataAccess access)
        {
            IDBControl ctrl = access as IDBControl;
            if (ctrl != null)
                ctrl.Open();
        }

        public void Commit(IDataAccess access)
        {
            IDBControl ctrl = access as IDBControl;
            if (ctrl != null)
                ctrl.Commit();
        }

        public void Close(IDataAccess access)
        {
            IDBControl ctrl = access as IDBControl;
            if (ctrl != null)
                ctrl.Close();
        }

        #endregion
    }
}
